﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;  
namespace ITXTEST
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ITXTESTData ITXTESTData = new ITXTEST.ITXTESTData();
           OracleENMQ();
           OracleDEMQ();
        }
        public void OracleENMQ()
        {
            string _connstring = "Data Source=intex1;User Id=intex;Password=intex;";
            OracleConnection _connObj = new OracleConnection(_connstring);

            // Create a new queue object
            OracleAQQueue _queueObj = new OracleAQQueue("MESSAGE_QUEUE", _connObj);
            _connObj.Open();

            OracleTransaction _txn = _connObj.BeginTransaction();

            // Set the payload type to your UDT
            _queueObj.MessageType = OracleAQMessageType.Raw;
            OracleAQMessage _msg = new OracleAQMessage();
            _msg.Payload = "tEST";
            // Enqueue the message
            _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
            _queueObj.Enqueue(_msg);

            _txn.Commit();
            _queueObj.Dispose();
            _connObj.Close();
            _connObj.Dispose();
            _connObj = null;

        }
        public void OracleDEMQ()
        {
            string _connstring = "Data Source=intex1;User Id=intex;Password=intex;";
            OracleConnection _connObj = new OracleConnection(_connstring);

            // Create a new queue object
            OracleAQQueue _queueObj = new OracleAQQueue("UDT_NAME", _connObj);

            // Set the payload type to your UDT
            _queueObj.MessageType = OracleAQMessageType.Raw;
            _connObj.Open();
            OracleTransaction _txn = _connObj.BeginTransaction();
            // Dequeue the message.
            _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
            _queueObj.DequeueOptions.Wait = 10;
            OracleAQMessage _deqMsg = _queueObj.Dequeue();
            _txn.Commit();
            _queueObj.Dispose();
            _connObj.Close();
            _connObj.Dispose();
            _connObj = null;


        }
    }
}
